/*
 * Copyright (C) 2022 KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <https://www.gnu.org/licenses/>.
 */

#include "launcheritem.h"
struct LauncherItemPrivate {
    QString name;
    int id;
    int type;
    int index;
    int pageIndex = -1;
    QString icon;
    QString desktopFile;
    QList<int> categories;
    int location;
    int rowSpan;
    int columnSpan;
    int state = LauncherItem::Normal;
    bool selected = false;
    bool appOpen = false;
    int windowId = -1;
    bool nameVisible = true;
    QAbstractListModel *model = nullptr;
    QString qmlFile;
    bool uninstallable = true;
    bool titleEditable = false;
    bool containerEditable = false;
    int containerCategory = -1;
};

LauncherItem::LauncherItem(QObject *parent)
    : QObject(parent)
    , p(new LauncherItemPrivate())
{

}

LauncherItem::LauncherItem(const LauncherItem &other)
    : LauncherItem(other.parent())
{
    this->setName(other.name());
    this->setId(other.id());
    this->setType(other.type());
    this->setPageIndex(other.pageIndex());
    this->setIcon(other.icon());
    this->setDesktopFile(other.desktopFile());
    this->setCategories(other.categories());
    this->setLocation(other.location());
    this->setRowSpan(other.rowSpan());
    this->setColumnSpan(other.columnSpan());
    this->setState(other.state());
    this->setSelected(other.selected());
    this->setAppOpen(other.appOpen());
    this->setWindowId(other.windowId());
    this->setNameVisible(other.nameVisible());
    this->setModel(other.model());
    this->setQmlFile(other.qmlFile());
    this->setUninstallable(other.uninstallable());
    this->setTitleEditable(other.titleEditable());
    this->setContainerEditable(other.containerEditable());
    this->setContainerCategory(other.containerCategory());
}

LauncherItem::~LauncherItem()
{
    delete p;
}

LauncherItem &LauncherItem::operator=(const LauncherItem &other)
{
    this->setName(other.name());
    this->setId(other.id());
    this->setType(other.type());
    this->setPageIndex(other.pageIndex());
    this->setIcon(other.icon());
    this->setDesktopFile(other.desktopFile());
    this->setCategories(other.categories());
    this->setLocation(other.location());
    this->setRowSpan(other.rowSpan());
    this->setColumnSpan(other.columnSpan());
    this->setState(other.state());
    this->setSelected(other.selected());
    this->setAppOpen(other.appOpen());
    this->setWindowId(other.windowId());
    this->setNameVisible(other.nameVisible());
    this->setModel(other.model());
    this->setQmlFile(other.qmlFile());
    this->setUninstallable(other.uninstallable());
    this->setTitleEditable(other.titleEditable());
    this->setContainerEditable(other.containerEditable());
    this->setContainerCategory(other.containerCategory());

    return *this;
}

QString LauncherItem::name() const
{
    return p->name;
}

void LauncherItem::setName(const QString &name)
{
    if (p->name != name) {
        p->name = name;
        Q_EMIT nameChanged();
    }
}

int LauncherItem::id() const
{
    return p->id;
}

void LauncherItem::setId(const int &id)
{
    if (p->id != id) {
        p->id = id;
        Q_EMIT idChanged();
    }
}

int LauncherItem::type() const
{
    return p->type;
}

void LauncherItem::setType(const int &type)
{
    if (p->type != type) {
        p->type = type;
        Q_EMIT typeChanged();
    }
}

int LauncherItem::pageIndex() const
{
    return p->pageIndex;
}

void LauncherItem::setPageIndex(const int &pageIndex)
{
    if (p->pageIndex != pageIndex) {
        p->pageIndex = pageIndex;
        Q_EMIT pageIndexChanged();
    }
}

QString LauncherItem::icon() const
{
    return p->icon;
}

void LauncherItem::setIcon(const QString &icon)
{
    if (p->icon != icon) {
        p->icon = icon;
        Q_EMIT iconChanged();
    }
}

QString LauncherItem::desktopFile() const
{
    return p->desktopFile;
}

void LauncherItem::setDesktopFile(const QString &desktopFile)
{
    if (p->desktopFile != desktopFile) {
        p->desktopFile = desktopFile;
        Q_EMIT desktopFileChanged();
    }
}

QList<int> LauncherItem::categories() const
{
    return p->categories;
}

void LauncherItem::setCategories(const QList<int> &categories)
{
    if (p->categories != categories) {
        p->categories = categories;
        Q_EMIT categoriesChanged();
    }
}

int LauncherItem::location() const
{
    return p->location;
}

void LauncherItem::setLocation(const int &location)
{
    if (p->location != location) {
        p->location = location;
        Q_EMIT locationChanged();
    }
}

int LauncherItem::rowSpan() const
{
    return p->rowSpan;
}

void LauncherItem::setRowSpan(const int &rowSpan)
{
    if (p->rowSpan != rowSpan) {
        p->rowSpan = rowSpan;
        Q_EMIT rowSpanChanged();
    }
}

int LauncherItem::columnSpan() const
{
    return p->columnSpan;
}

void LauncherItem::setColumnSpan(const int &columnSpan)
{
    if (p->columnSpan != columnSpan) {
        p->columnSpan = columnSpan;
        Q_EMIT columnSpanChanged();
    }
}

int LauncherItem::state() const
{
    return p->state;
}

void LauncherItem::setState(const int &state)
{
    if (p->state != state) {
        p->state = state;
        Q_EMIT stateChanged();
    }
}

bool LauncherItem::selected() const
{
    return (p->selected && p->state == LauncherItem::Selectable);
}

void LauncherItem::setSelected(bool selected)
{
    if (p->selected != selected && p->state == LauncherItem::Selectable) {
        p->selected = selected;
        Q_EMIT selectedChanged();
    }
}

bool LauncherItem::appOpen() const
{
    return p->appOpen;
}

void LauncherItem::setAppOpen(const bool &appOpen)
{
    if (p->appOpen != appOpen) {
        p->appOpen = appOpen;
        Q_EMIT appOpenChanged();
    }
}

int LauncherItem::windowId() const
{
    return p->windowId;
}
void LauncherItem::setWindowId(const int &windowId)
{
    if (p->windowId != windowId) {
        p->windowId = windowId;
        Q_EMIT windowIdChanged();
    }
}

bool LauncherItem::nameVisible() const
{
    return p->nameVisible;
}

void LauncherItem::setNameVisible(const bool &nameVisible)
{
    if (p->nameVisible != nameVisible) {
        p->nameVisible = nameVisible;
        Q_EMIT nameVisibleChanged();
    }
}

QAbstractListModel *LauncherItem::model() const
{
    return p->model;
}

void LauncherItem::setModel(QAbstractListModel *model)
{
    if (p->model != model) {
        p->model = model;
        Q_EMIT modelChanged();
    }
}

QString LauncherItem::qmlFile() const
{
    return p->qmlFile;
}

void LauncherItem::setQmlFile(const QString &qmlFile)
{
    if (p->qmlFile != qmlFile) {
        p->qmlFile = qmlFile;
        Q_EMIT qmlFileChanged();
    }
}

bool LauncherItem::uninstallable() const
{
    return  p->uninstallable;
}

void LauncherItem::setUninstallable(const bool &uninstallable)
{
    if (p->uninstallable != uninstallable) {
        p->uninstallable = uninstallable;
        Q_EMIT uninsatllableChanged();
    }
}

bool LauncherItem::titleEditable() const
{
    return p->titleEditable;
}

void LauncherItem::setTitleEditable(const bool &editable)
{
    if (p->titleEditable != editable) {
        p->titleEditable = editable;
        Q_EMIT titleEditableChanged();
    }
}

bool LauncherItem::containerEditable() const
{
    return p->containerEditable;
}

void LauncherItem::setContainerEditable(const bool &editable)
{
    if (p->containerEditable != editable) {
        p->containerEditable = editable;
        Q_EMIT containerEditableChanged();
    }
}

int LauncherItem::containerCategory() const
{
    return p->containerCategory;
}

void LauncherItem::setContainerCategory(const int &category)
{
    if (p->containerCategory != category) {
        p->containerCategory = category;
        Q_EMIT containerCategoryChanged();
    }
}
